home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung CD 2 (Tewi)(1994).iso
/
c
/
compcomp
/
os2yacc
/
yg2out.3c
< prev
next >
Wrap
Text File
|
1989-09-29
|
2KB
|
77 lines
/*
HEADER: CUG nnn.nn;
TITLE: YACC - Yet Another Compilier-Compilier
VERSION: 1.0 for IBM-PC
DATE: JAN 28, 1985
DESCRIPTION: LALR(1) Parser Generator. From UNIX
KEYWORDS: Parser Generator Compilier-Compilier YACC
SYSTEM: IBM-PC and Compatiables
FILENAME: YG2OUT.3C
WARNINGS: This program is not for the casual user. It will
be useful primarily to expert developers.
CRC: N/A
SEE-ALSO: LEX and PREP
AUTHORS: Scott Guthery 11100 leafwood lane Austin, TX 78750
COMPILERS: DESMET-C
REFERENCES: UNIX Systems Manuals
*/
#include "y3.h"
void go2out( void )
{
/* output the gotos for the nontermninals */
int i, j, k, best, count, cbest, times;
fprintf( ftemp, "$\n" ); /* mark begining of gotos */
for( i=1; i<=nnonter; ++i )
{
go2gen(i);
/* find the best one to make default */
best = -1;
times = 0;
for( j=0; j<=nstate; ++j )
{
/* is j the most frequent */
if( tystate[j] == 0 ) continue;
if( tystate[j] == best ) continue;
/* is tystate[j] the most frequent */
count = 0;
cbest = tystate[j];
for( k=j; k<=nstate; ++k ) if( tystate[k]==cbest ) ++count;
if( count > times )
{
best = cbest;
times = count;
}
}
/* best is now the default entry */
zzgobest += (times-1);
for( j=0; j<=nstate; ++j )
{
if( tystate[j] != 0 && tystate[j]!=best )
{
fprintf( ftemp, "%d,%d,", j, tystate[j] );
zzgoent += 1;
}
}
/* now, the default */
zzgoent += 1;
fprintf( ftemp, "%d\n", best );
}
}